import java.io.IOException;

import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.server.PropertyHandlerMapping;
import org.apache.xmlrpc.server.XmlRpcServer;
import org.apache.xmlrpc.webserver.WebServer;


public class LaunchClient {

	public static JFrameClient jframe = new JFrameClient();
	private WebServer server;
	private PropertyHandlerMapping phm;
	private XmlRpcServer xmlRpcServer;

	public void startBusiness(){
		jframe.setVisible(true);
		launchServer();
	}
	
	
	/**
	 *accept updated time from server 
	 * @throws XmlRpcException
	 * @throws IOException
	 */
	public void launchServer(){
		server = new WebServer(Integer.valueOf(XMLUtil.clientPort));
		 phm = new PropertyHandlerMapping();
	     try {
			phm.addHandler("sample", LaunchClient.class);
			xmlRpcServer = server.getXmlRpcServer();
		    xmlRpcServer.setHandlerMapping(phm);
		    server.start();
		} catch (XmlRpcException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	     
	}
	
	public Integer timeAccept(String time){
		LaunchClient.jframe.setCurrentTime(time);
		return new Integer(0);
	}

	public static void main(String[] args){
		XMLUtil.fetchXML();
		LaunchClient client = new LaunchClient();
		client.startBusiness();
	}
}
